package com.weixing.mall.provider.controller.cms;


import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.Closure;
import com.weixing.mall.provider.service.IClosureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  系统上传
 * </p>
 *
 * @author Small
 * @since 2020-04-23
 */
@RestController
@RequestMapping("/closure")
@Api(value = "系统上传附件APi", tags = "系统上传附件")
public class ClosureController extends BaseController {

   @Autowired
    private IClosureService closureService;

    @ApiOperation(value = "加载附件列表")
    @GetMapping("")
    public Result list() {
        return ResultUtil.success(closureService.selectOfPage(initMpPage()));
    }

    @ApiOperation(value = "添加/修改")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save( Closure closure){
        if(closure.getId()==null){
            closureService.save(closure);
        }else{
            closureService.updateById(closure);
        }

        return  ResultUtil.success();
    }
    @ApiOperation(value = "删除")
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return closureService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "加载附件信息")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable Long id) {
        return ResultUtil.success(closureService.getById(id));
    }

    @ApiOperation(value = "根据编码获取下载地址")
    @GetMapping("load/{code}")
    public Result loadByCode(@PathVariable String code) {
        return ResultUtil.success(closureService.loadByCode(code));
    }
}
